/**
 * @program: LeetCode
 * @description: LeetCode :
 * @author: WXY
 * @create: 2023-01-07 20:44
 * @Version 1.0
 **/
public class Num152_maxProduct {
    public static int maxProduct(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int ans = Integer.MIN_VALUE;
        int cur = 1;
        for (int i = left; i < nums.length - 1; i++) {
            cur = cur != 0 ? cur * nums[i] : nums[i];
            ans = Math.max(ans, cur);
        }
        cur = 1;
        for (int i = right; i >= 0; i--) {
            cur = cur != 0 ? cur * nums[i] : nums[i];
            ans = Math.max(cur, ans);
        }
        return ans;
    }

    private static void swap(int max, int min) {
        int temp = max;
        max = min;
        min = max;
    }

    public static void main(String[] args) {
        int[] arr = {1, 2, 6, 0, 2, 4};
        int i = maxProduct(arr);
        System.out.println(i);
    }
}
